package simpleftp.server;

import java.net.ServerSocket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Simple serveur TCP creant des thread pour gerer chaque connexion client.
 * 
 * @author lom
 */
public class FTPServerMain {

	/**
	 * Port d'ecoute.
	 */
	public static final int PORT = 7802;
	/**
	 * Socket serveur d'accueil.
	 */
	private static ServerSocket socketaccueil;

	public static void main(String argv[]) throws Exception 
	{
		//creation of the pool
		ExecutorService executorPool = Executors.newFixedThreadPool(10);	
		
		try {
			//creation of the listener
			socketaccueil = new ServerSocket(PORT);
			System.out.println("Server up and running.");
			FTPServer.setDebug(true);
			
			//listen to the port and when a new connection is ask put it in the pool
			while (true) {
				
				FTPServer server = new FTPServer(socketaccueil.accept());
				executorPool.submit(server);				
			}
		} finally {
			//close the pool and the listener to socket
			executorPool.shutdownNow();
			if (socketaccueil != null) {
				socketaccueil.close();
			}
		}
	}
}
